﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using YourControl.Resources.Model;

namespace YourControl.ViewPicture.UserControls
{
    public partial class AlbumControl
    {
        public AlbumControl() : this(null)
        {
            
        }

        public AlbumControl(List<Item> items)
        {
            InitializeComponent();
            LoadResources(items);
        }

        private void LoadResources(List<Item> items)
        {
            if (items == null) return;
            for (var i = 0; i < items.Count;i++ )
            {
                var item = items[i];
                var imageSource = new BitmapImage(new Uri(item.Thumbnail, UriKind.RelativeOrAbsolute));
                var pictureBox = new PictureBoxControl();
                pictureBox.Source = imageSource;
                var random = new Random(i*10000);
                var ticket =  random.Next(-10, 10);
                pictureBox.RenderTransform = new RotateTransform(ticket);
                pictureBox.RenderTransformOrigin = new Point(0.5,0.5);
                Layout.Children.Add(pictureBox);
            }
        }
    }
}
